# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Maintainer: Ray Donnelly <mingw.android@gmail.com>

_realname=gtk3
_branch=gtk-3-22
pkgbase=mingw-w64-${_realname}-git
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=3.22.3.21.gd3bdd38
pkgrel=1
pkgdesc="GObject-based multi-platform GUI toolkit (git $_branch) (mingw-w64)"
arch=('any')
url="https://www.gtk.org/"
license=("LGPL")
install=gtk3-${CARCH}.install
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-python2"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection")
# python2 is required to run gdbus-codegen
makedepends+=("autoconf" "automake" "libtool" "gtk-doc" "git"
              "autoconf-archive")
# autotools are required because several Makefile.am are modified
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-adwaita-icon-theme"
         "${MINGW_PACKAGE_PREFIX}-atk"
         "${MINGW_PACKAGE_PREFIX}-cairo"
         "${MINGW_PACKAGE_PREFIX}-gdk-pixbuf2"
         "${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-json-glib"
         "${MINGW_PACKAGE_PREFIX}-libepoxy"
         "${MINGW_PACKAGE_PREFIX}-pango"
         "${MINGW_PACKAGE_PREFIX}-shared-mime-info")
options=('!strip' 'debug')
source=("${_realname}::git+https://git.gnome.org/browse/gtk+#branch=${_branch}")
sha256sums=('SKIP')

pkgver() {
  cd "${srcdir}"/${_realname}
  git describe --tags | sed 's|-|.|g'
}

prepare() {
  cd "${srcdir}"/${_realname}
  [[ -f gtk-doc.make ]] || cp /usr/share/gtk-doc/data/gtk-doc.make .
  [[ -f README ]] || echo "missing" > README
  autoreconf -vfi
}

build() {
  #export GI_SCANNER_DEBUG="save-temps"
  [[ -d build-${MINGW_CHOST} ]] && rm -rf build-${MINGW_CHOST}
  cp -rf gtk3 build-${MINGW_CHOST}
  cd build-${MINGW_CHOST}

  PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:/usr/share/pkgconfig" \
  ./configure \
    --prefix=${MINGW_PREFIX} \
    --{build,host}=${MINGW_CHOST} \
    --enable-win32-backend \
    --enable-shared \
    --enable-introspection \
    --enable-broadway-backend \
    --disable-cups \
    --with-included-immodules \
    --enable-silent-rules

  make V=1
}

package() {
  cd "${srcdir}"/build-${MINGW_CHOST}
  make -j1 DESTDIR="${pkgdir}" install
  find "${pkgdir}"${MINGW_PREFIX} -name '*.def' -o -name '*.exp' -o -name '*.manifest' | xargs -rtl1 rm

  mv "${pkgdir}"${MINGW_PREFIX}/bin/gtk-update-icon-cache{,-3.0}.exe
  mv "${pkgdir}"${MINGW_PREFIX}/share/man/man1/gtk-update-icon-cache{,-3.0}.1

  install -Dm644 "${srcdir}"/${_realname}/COPYING "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/COPYING
}
